import request from '@/utils/request' // 引入封装得axios

// 获取新闻列表
export function getModelPage10 (modelname,params) {
    var url = ""
    console.log(params)
    if((params.userid != undefined) && (params.userid != "")){
        if(modelname == "users"){
            url = '/api/querylimit/'+modelname+'/select%7C*/where%7Cid=@'+params.userid+'@%20order%20by%20'+params.order_column+'%20'+params.desc+'/0/'+params.size;
        }else{
            url = '/api/querylimit/'+modelname+'/select%7C*/where%7Cuserid=@'+params.userid+'@%20order%20by%20'+params.order_column+'%20'+params.desc+'/0/'+params.size;
        }
    }else{
        url = '/api/querylimit/'+modelname+'/select%7C*/where%7C1%20order%20by%20'+params.order_column+'%20'+params.desc+'/0/'+params.size;
    }
    if(("select" in params) && (params.select != "")){
        url = url.replace("*",params.select)
    }
    console.log(url)
    return request({
        url: url,
        method: 'GET'
    })
}

// 获取新闻列表
export function getModels (modelname,params) {
    var url = ""
    console.log(params)
    if((params.userid != undefined) && (params.userid != "")){
        if(modelname == "users"){
            url = '/api/querylimit/'+modelname+'/select%7C*/where%7Cid=@'+params.userid+'@%20order%20by%20'+params.order_column+'%20'+params.desc+'/'+params.start+'/'+params.end;
        }else{
            url = '/api/querylimit/'+modelname+'/select%7C*/where%7Cuserid=@'+params.userid+'@%20order%20by%20'+params.order_column+'%20'+params.desc+'/'+params.start+'/'+params.end;
        }
    }else{
        url = '/api/querylimit/'+modelname+'/select%7C*/where%7C1%20order%20by%20'+params.order_column+'%20'+params.desc+'/'+params.start+'/'+params.end;
    }
    if(("select" in params) && (params.select != "")){
        url = url.replace("*",params.select)
    }
    return request({
        url: url,
        method: 'GET'
    })
}


// 获取新闻列表
export function getModelsColume (modelname) {
    console.log(modelname)
    return request({
        url: '/api/get_structure/'+modelname,
        method: 'GET'
    })
}

// 获取新闻列表
export function getModelsData (modelname,id) {
    return request({
        url: '/api/query/'+modelname+'/select%7C*/where%7Cid=@'+id+'@',
        method: 'GET'
    })
}

// 获取新闻列表
export function getModelsDataCondition (modelname,params) {
    var url = '/api/query_href'
    return request({
        url: url,
        method: 'GET'
    })
}

export function editModels (modelname,params) {
    delete params["tablename"]
    return request({
        url: '/api/update/'+modelname+'/'+params.id,
        method: 'post',
        data: params
    })
}

export function addModels (modelname,params) {
    delete params["tablename"]
    return request({
        url: '/api/add/'+modelname,
        method: 'post',
        data: params
    })
}

export function deleteModels (modelname,id) {
    return request({
        url: '/api/delete/'+modelname+'/'+id,
        method: 'post'
    })
}
